package com.cp.admin.modular.user.controller;

import com.cp.admin.modular.user.model.UserPhoto;
import com.cp.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.cp.admin.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.cp.admin.modular.user.service.IUserPhotoService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2020-08-28 14:03:07
 */
@Controller
@RequestMapping("/userPhoto")
public class UserPhotoController extends BaseController {

    private String PREFIX = "/user/userPhoto/";

    @Autowired
    private IUserPhotoService userPhotoService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "userPhoto.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/userPhoto_add")
    public String userPhotoAdd() {
        return PREFIX + "userPhoto_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/userPhoto_update/{userPhotoId}")
    public String userPhotoUpdate(@PathVariable Long userPhotoId, Model model) {
        UserPhoto userPhoto = userPhotoService.selectById(userPhotoId);
        model.addAttribute("item",userPhoto);
        LogObjectHolder.me().set(userPhoto);
        return PREFIX + "userPhoto_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return userPhotoService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UserPhoto userPhoto) {
        userPhotoService.insert(userPhoto);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long userPhotoId) {
        userPhotoService.deleteById(userPhotoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UserPhoto userPhoto) {
        userPhotoService.updateById(userPhoto);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{userPhotoId}")
    @ResponseBody
    public Object detail(@PathVariable("userPhotoId") Long userPhotoId) {
        return userPhotoService.selectById(userPhotoId);
    }
}
